package com.apes.fn.crm.customComplain;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.apes.framework.query.ApesDao;
import org.springframework.stereotype.Component;

@Component
public class FnCustomComplainReportDao extends ApesDao {



    public JSONArray customPlainHandleEfficiencyDept(JSONObject param){
        String sSQL = "SELECT C.INITIAT_OA_DATE, NVL(D.TOTAL, 0) TOTAL, NVL(D.HANDLED, 0) HANDLED,\n" +
                "       NVL(D.HANDLED_CONSUME, 0) HANDLED_CONSUME,\n" +
                "       ROUND((CASE\n" +
                "               WHEN NVL(D.HANDLED, 0) = 0 THEN\n" +
                "                0\n" +
                "               ELSE\n" +
                "                NVL(D.HANDLED_CONSUME, 0) / NVL(D.HANDLED, 0)\n" +
                "             END), 2) AVERAGE_HANDLED_CONSUME\n" +
                "  FROM (\n" +
                "         -- 周期\n" +
                "         \nSELECT TO_CHAR(ADD_MONTHS(TO_DATE(:DATE_START, 'yyyy-MM'), ROWNUM - 1),\n" +
                "                          'yyyy-MM') INITIAT_OA_DATE\n" +
                "           FROM DUAL\n" +
                "         CONNECT BY ROWNUM <=\n" +
                "                    MONTHS_BETWEEN(TO_DATE(:DATE_END, 'yyyy-MM'),\n" +
                "                                   TO_DATE(:DATE_START, 'yyyy-MM')) + 1) C\n" +
                "  LEFT JOIN (SELECT TO_CHAR(A.INITIAT_OA_DATE, 'YYYY-MM') INITIAT_OA_DATE,\n" +
                "                    COUNT(A.ID) TOTAL,\n" +
                "                    -- 已处理\n" +
                "                    \n(SELECT COUNT(*)\n" +
                "                        FROM FN_CUSTOM_COMPLAIN B\n" +
                "                       WHERE TO_CHAR(A.INITIAT_OA_DATE, 'YYYY-MM') =\n" +
                "                             TO_CHAR(B.INITIAT_OA_DATE, 'YYYY-MM')\n" +
                "                         AND TO_CHAR(B.END_DATE, 'YYYY-MM') =\n" +
                "                             TO_CHAR(B.INITIAT_OA_DATE, 'YYYY-MM')) HANDLED,\n" +
                "                    -- 总耗时\n" +
                "                    \n(SELECT SUM(ROUND(TO_NUMBER((B.END_DATE + 0) -\n" +
                "                                                  (B.INITIAT_OA_DATE + 0)) * 24 * 60))\n" +
                "                        FROM FN_CUSTOM_COMPLAIN B\n" +
                "                       WHERE TO_CHAR(A.INITIAT_OA_DATE, 'YYYY-MM') =\n" +
                "                             TO_CHAR(B.INITIAT_OA_DATE, 'YYYY-MM')\n" +
                "                         AND TO_CHAR(B.END_DATE, 'YYYY-MM') =\n" +
                "                             TO_CHAR(B.INITIAT_OA_DATE, 'YYYY-MM')) HANDLED_CONSUME\n" +
                "               FROM FN_CUSTOM_COMPLAIN A\n" +

                (param.getJSONArray("DEPT_ID") != null && param.getJSONArray("DEPT_ID").size() > 0 ? ("WHERE A.DEPT_ID IN "+ getInParam(param.getJSONArray("DEPT_ID")) +"\n"): "") +

                "              GROUP BY TO_CHAR(A.INITIAT_OA_DATE, 'YYYY-MM')) D\n" +
                "    ON C.INITIAT_OA_DATE = D.INITIAT_OA_DATE\n" +
                " WHERE 1 = 1\n" +
                " ORDER BY C.INITIAT_OA_DATE";

        return toJSONArray(find(sSQL, param));
    }


    public JSONArray customPlainHandleEfficiencyPerson(JSONObject param){
        String sSQL = "/*声明临时表*/ \n" +
                "WITH IR_LOGGER_COMPLAIN AS\n" +
                " (SELECT ROW_NUMBER() OVER(ORDER BY T.BUSINESS_KEY, T.CREATE_DATE) AS ROW_NUM,\n" +
                "         T.BUSINESS_KEY, T.CREATE_DATE, T.ID, T.OPERATE, T.OPERATOR_ID\n" +
                "    FROM IR_LOGGER T\n" +
                "   WHERE T.BUSINESS_TYPE = 'FnCustomComplain'\n" +
                "     AND T.OPERATE IN ('客诉处理：申请结单', '部门回访：结单', '部门回访：拒绝'))\n" +
                "/*从日志表内部取最近的两个客服处理记录，取时间差值*/ \n" +
                "SELECT *\n" +
                "  FROM (SELECT CREATE_DATE, OPERATOR_ID,\n" +
                "                (SELECT NAME FROM AUT_USERS D WHERE D.ID = OPERATOR_ID) OPERATOR_NAME,\n" +
                "                ROUND(SUM(CONSUME) / COUNT(*), 2) AVERAGE_CONSUME,\n" +
                "                COUNT(*) TASK\n" +
                "           FROM (SELECT TO_CHAR(A.CREATE_DATE, 'YYYY-MM') CREATE_DATE, A.ID,\n" +
                "                         A.OPERATE, A.ROW_NUM, A.BUSINESS_KEY, A.OPERATOR_ID,\n" +
                "                         (SELECT ROUND(GET_DATE_DIFFERENCE(A.CREATE_DATE , B.CREATE_DATE) * 24 * 60)\n" +
                "                             FROM IR_LOGGER_COMPLAIN B\n" +
                "                            WHERE B.ROW_NUM = A.ROW_NUM - 1\n" +
                "                              AND A.CREATE_DATE > B.CREATE_DATE\n" +
                "                              AND A.BUSINESS_KEY = B.BUSINESS_KEY) CONSUME\n" +
                "                    FROM IR_LOGGER_COMPLAIN A\n" +
                "                   WHERE EXISTS (SELECT *\n" +
                "                            FROM IR_LOGGER_COMPLAIN C\n" +
                "                           WHERE A.BUSINESS_KEY = C.BUSINESS_KEY\n" +
                "                             AND C.OPERATE = '客诉处理：申请结单')\n" +
                "                     AND A.OPERATE IN ('部门回访：结单', '部门回访：拒绝')\n" +
                "                   ORDER BY TO_CHAR(A.CREATE_DATE, 'YYYY-MM'), A.OPERATOR_ID)\n" +
                "          GROUP BY CREATE_DATE, OPERATOR_ID)\n" +
                " WHERE CREATE_DATE = :DATE_START\n" +
                "    OR CREATE_DATE = :DATE_END\n" +
                " ORDER BY CREATE_DATE, OPERATOR_NAME\n";

        return toJSONArray(find(sSQL, param));
    }


    public JSONArray customPlainCountAndConsume(JSONObject param){
        String sSQL =  "SELECT *\n" +
                "  FROM (SELECT C.INITIAT_OA_DATE, NVL(SUM(D.DISPOSE_NUM), 0) DISPOSE_NUM,\n" +
                "                NVL(SUM(D.STOP_NUM), 0) STOP_NUM,\n" +
                "                NVL(SUM(D.END_NUM), 0) END_NUM,\n" +
                "                (CASE\n" +
                "                  WHEN SUM(D.END_NUM) = 0 THEN\n" +
                "                   0\n" +
                "                  ELSE\n" +
                "                   NVL(ROUND(SUM(D.CONSUME) / SUM(D.END_NUM), 2), 0)\n" +
                "                END) AVERAGE_CONSUME\n" +
                "           FROM ( /*周期*/\n" +
                "                  SELECT TO_CHAR(ADD_MONTHS(TO_DATE(:DATE_START, 'yyyy-MM'),\n" +
                "                                              ROWNUM - 1), 'yyyy-MM') INITIAT_OA_DATE\n" +
                "                    FROM DUAL\n" +
                "                  CONNECT BY ROWNUM <=\n" +
                "                             MONTHS_BETWEEN(TO_DATE(:DATE_END, 'yyyy-MM'),\n" +
                "                                            TO_DATE(:DATE_START, 'yyyy-MM')) + 1) C\n" +
                "           LEFT JOIN (SELECT INITIAT_OA_DATE, DEPT_ID,\n" +
                "                            SUM(DISPOSE_NUM) DISPOSE_NUM,\n" +
                "                            SUM(STOP_NUM) STOP_NUM, SUM(END_NUM) END_NUM,\n" +
                "                            SUM(CONSUME) CONSUME\n" +
                "                       FROM ( /*处理中*/\n" +
                "                              SELECT TO_CHAR(A.INITIAT_OA_DATE, 'YYYY-MM') INITIAT_OA_DATE,\n" +
                "                                      A.DEPT_ID, COUNT(*) DISPOSE_NUM, 0 STOP_NUM,\n" +
                "                                      0 END_NUM, 0 CONSUME\n" +
                "                                FROM FN_CUSTOM_COMPLAIN A\n" +
                "                               WHERE A.INITIAT_OA_DATE IS NOT NULL\n" +
                "                                 AND A.STATE = 'disposing'\n" +
                "                                 AND A.ACTIVE = 1\n" +
                "                               GROUP BY TO_CHAR(A.INITIAT_OA_DATE, 'YYYY-MM'),\n" +
                "                                         A.DEPT_ID\n" +
                "                              UNION ALL /*停单中*/\n" +
                "                              SELECT TO_CHAR(A.INITIAT_OA_DATE, 'YYYY-MM') INITIAT_OA_DATE,\n" +
                "                                      A.DEPT_ID, 0 DISPOSE_NUM, COUNT(*) STOP_NUM,\n" +
                "                                      0 END_NUM, 0 CONSUME\n" +
                "                                FROM FN_CUSTOM_COMPLAIN A\n" +
                "                               WHERE A.INITIAT_OA_DATE IS NOT NULL\n" +
                "                                 AND A.STATE = 'disposing'\n" +
                "                                 AND A.ACTIVE = 0\n" +
                "                               GROUP BY TO_CHAR(A.INITIAT_OA_DATE, 'YYYY-MM'),\n" +
                "                                         A.DEPT_ID\n" +
                "                              UNION ALL /*已结单*/\n" +
                "                              SELECT TO_CHAR(A.INITIAT_OA_DATE, 'YYYY-MM') INITIAT_OA_DATE,\n" +
                "                                      A.DEPT_ID, 0 DISPOSE_NUM, 0 STOP_NUM,\n" +
                "                                      COUNT(*) END_NUM, 0 CONSUME\n" +
                "                                FROM FN_CUSTOM_COMPLAIN A\n" +
                "                               WHERE A.INITIAT_OA_DATE IS NOT NULL\n" +
                "                                 AND A.STATE = 'end'\n" +
                "                               GROUP BY TO_CHAR(A.INITIAT_OA_DATE, 'YYYY-MM'),\n" +
                "                                         A.DEPT_ID\n" +
                "                              UNION ALL\n" +
                "                              SELECT TO_CHAR(A.INITIAT_OA_DATE, 'YYYY-MM') INITIAT_OA_DATE,\n" +
                "                                      A.DEPT_ID, 0 DISPOSE_NUM, 0 STOP_NUM,\n" +
                "                                      0 END_NUM,\n" +
                "                                      SUM(TO_NUMBER((A.END_DATE + 0) -\n" +
                "                                                     (A.INITIAT_OA_DATE + 0)) * 24 * 60) CONSUME\n" +
                "                                FROM FN_CUSTOM_COMPLAIN A\n" +
                "                               WHERE A.INITIAT_OA_DATE IS NOT NULL\n" +
                "                                 AND A.STATE = 'end'\n" +
                "                               GROUP BY TO_CHAR(A.INITIAT_OA_DATE, 'YYYY-MM'),\n" +
                "                                         A.DEPT_ID)\n" +
                "                      WHERE 1 = 1\n" +
                "                      GROUP BY DEPT_ID, INITIAT_OA_DATE) D\n" +
                "             ON C.INITIAT_OA_DATE = D.INITIAT_OA_DATE\n" +

                 (param.getJSONArray("DEPT_ID") != null && param.getJSONArray("DEPT_ID").size() > 0 ? ("WHERE D.DEPT_ID IN "+ getInParam(param.getJSONArray("DEPT_ID")) +"\n"): "") +
                        "          GROUP BY C.INITIAT_OA_DATE)\n" +
                " ORDER BY INITIAT_OA_DATE\n";

        return toJSONArray(find(sSQL, param));
    }


    public JSONArray customPlainSatisfaction(JSONObject param){
        String sSQL = "SELECT * FROM (\n" +
                " SELECT TO_CHAR(B.INITIAT_OA_DATE, 'YYYY-MM') INITIAT_OA_DATE,\n" +
                "        SUM(B.COMMON_NUM) COMMON_NUM, SUM(B.SATISFY_NUM) SATISFY_NUM,\n" +
                "        SUM(B.VERY_SATISFY_NUM) VERY_SATISFY_NUM,\n" +
                "        SUM(B.UNSATISFY_NUM) UNSATISFY_NUM,\n" +
                "        SUM(B.VERY_UNSATISFY_NUM) VERY_UNSATISFY_NUM\n" +
                "   FROM (SELECT A.INITIAT_OA_DATE, A.DEPT_ID,\n" +
                "            (CASE WHEN GET_ENUMERATION_NAME(A.CUSTOM_SATISFACTION, 'customSatisfaction') = '一般' THEN 1 ELSE 0 END ) COMMON_NUM,\n" +
                "            (CASE WHEN GET_ENUMERATION_NAME(A.CUSTOM_SATISFACTION, 'customSatisfaction') = '满意' THEN 1 ELSE 0 END ) SATISFY_NUM,\n" +
                "            (CASE WHEN GET_ENUMERATION_NAME(A.CUSTOM_SATISFACTION, 'customSatisfaction') = '非常满意' THEN 1 ELSE 0 END ) VERY_SATISFY_NUM,\n" +
                "            (CASE WHEN GET_ENUMERATION_NAME(A.CUSTOM_SATISFACTION, 'customSatisfaction') = '不满意' THEN 1 ELSE 0 END ) UNSATISFY_NUM,\n" +
                "            (CASE WHEN GET_ENUMERATION_NAME(A.CUSTOM_SATISFACTION, 'customSatisfaction') = '非常不满意' THEN 1 ELSE 0 END ) VERY_UNSATISFY_NUM\n" +
                "            FROM FN_CUSTOM_COMPLAIN A\n" +
                "           WHERE A.INITIAT_OA_DATE IS NOT NULL\n" +
                "             AND A.END_DATE IS NOT NULL\n" +

                (param.getJSONArray("DEPT_ID") != null && param.getJSONArray("DEPT_ID").size() > 0 ? ("AND A.DEPT_ID IN "+ getInParam(param.getJSONArray("DEPT_ID")) +"\n"): "") +

                "             AND A.CUSTOM_SATISFACTION IS NOT NULL) B\n" +
                "  GROUP BY TO_CHAR(B.INITIAT_OA_DATE, 'YYYY-MM'))\n" +
                "  WHERE  INITIAT_OA_DATE = :DATE_START\n" +
                "    OR INITIAT_OA_DATE = :DATE_END\n" +
                " ORDER BY INITIAT_OA_DATE";

        return toJSONArray(find(sSQL, param));
    }


    public JSONArray customPlainRate(JSONObject param){
        String sSQL = "SELECT B.CREATE_DATE, NVL(C.CAR_NUMBER, 0) CAR_NUMBER,\n" +
                "       NVL(D.COMPLAIN_NUM, 0) COMPLAIN_NUM\n" +
                "  FROM (\n" +
                "         /*周期*/ \n" +
                "         \nSELECT TO_CHAR(ADD_MONTHS(TO_DATE(:DATE_START, 'yyyy-MM'), ROWNUM - 1),\n" +
                "                          'yyyy-MM') CREATE_DATE\n" +
                "           FROM DUAL\n" +
                "         CONNECT BY ROWNUM <=\n" +
                "                    MONTHS_BETWEEN(TO_DATE(:DATE_END, 'yyyy-MM'),\n" +
                "                                   TO_DATE(:DATE_START, 'yyyy-MM')) + 1) B\n" +
                "  LEFT JOIN\n" +
                "/*车流量*/ \n" +
                " \n(SELECT TO_CHAR(A.CREATE_DATE, 'YYYY-MM') CREATE_DATE, COUNT(*) CAR_NUMBER\n" +
                "    FROM FN_PICK_UP_CAR A\n" +

                (param.getJSONArray("DEPT_ID") != null && param.getJSONArray("DEPT_ID").size() > 0 ? (" WHERE A.DEPT_ID IN "+ getInParam(param.getJSONArray("DEPT_ID")) +"\n"): "") +

                "   GROUP BY TO_CHAR(A.CREATE_DATE, 'YYYY-MM')) C\n" +
                "    ON B.CREATE_DATE = C.CREATE_DATE\n" +
                "  LEFT JOIN\n" +
                "\n" +
                "/*客诉量*/ \n" +
                " \n(SELECT TO_CHAR(A.INITIAT_OA_DATE, 'YYYY-MM') CREATE_DATE,\n" +
                "         COUNT(*) COMPLAIN_NUM\n" +
                "    FROM FN_CUSTOM_COMPLAIN A\n" +
                "   WHERE A.INITIAT_OA_DATE IS NOT NULL\n" +

                (param.getJSONArray("DEPT_ID") != null && param.getJSONArray("DEPT_ID").size() > 0 ? (" AND A.DEPT_ID IN "+ getInParam(param.getJSONArray("DEPT_ID")) +"\n"): "") +

                "   GROUP BY TO_CHAR(A.INITIAT_OA_DATE, 'YYYY-MM')) D\n" +
                "    ON B.CREATE_DATE = D.CREATE_DATE\n" +
                " WHERE 1 = 1\n" +
                " ORDER BY B.CREATE_DATE\n";

        return toJSONArray(find(sSQL, param));
    }


    public JSONArray customPlainType(JSONObject param){
        String sSQL = "SELECT *\n" +
                "  FROM (SELECT B.INITIAT_OA_DATE, B.COMPLAIN_CATEGORY_NAME,\n" +
                "                B.COMPLAIN_TYPE_NAME, COUNT(B.ID) NUM\n" +
                "           FROM (SELECT A.ID,\n" +
                "                         TO_CHAR(A.INITIAT_OA_DATE, 'YYYY-MM') INITIAT_OA_DATE,\n" +
                "                         GET_ENUMERATION_NAME(A.COMPLAIN_CATEGORY,\n" +
                "                                               'complainCategory') COMPLAIN_CATEGORY_NAME,\n" +
                "                         GET_ENUMERATION_NAME(A.COMPLAIN_TYPE, 'complainType') COMPLAIN_TYPE_NAME\n" +
                "                    FROM FN_CUSTOM_COMPLAIN A\n" +
                "                   WHERE A.INITIAT_OA_DATE IS NOT NULL\n" +
                "                     AND A.COMPLAIN_CATEGORY IS NOT NULL\n" +

                (param.getJSONArray("DEPT_ID") != null && param.getJSONArray("DEPT_ID").size() > 0 ? (" AND A.DEPT_ID IN "+ getInParam(param.getJSONArray("DEPT_ID")) +"\n"): "") +

                "                     AND A.COMPLAIN_TYPE IS NOT NULL) B\n" +
                "          WHERE B.INITIAT_OA_DATE = :DATE_START\n" +
                "             OR B.INITIAT_OA_DATE = :DATE_END\n" +
                "          GROUP BY B.INITIAT_OA_DATE, B.COMPLAIN_CATEGORY_NAME,\n" +
                "                   B.COMPLAIN_TYPE_NAME)\n" +
                " ORDER BY INITIAT_OA_DATE, COMPLAIN_CATEGORY_NAME\n";

        return toJSONArray(find(sSQL, param));
    }


    public JSONArray customPlainCountRank(JSONObject param){
        String sSQL = "SELECT C.INITIAT_OA_DATE, C.DEPT_ID, C.DEPT_NAME,\n" +
                "       C.COMPLAIN_NUM CUR_COMPLAIN_NUM,\n" +
                "       NVL(D.COMPLAIN_NUM, 0) PREV_COMPLAIN_NUM\n" +
                "  FROM (SELECT *\n" +
                "           FROM (SELECT *\n" +
                "                    FROM (SELECT TO_CHAR(A.INITIAT_OA_DATE, 'YYYY-MM') INITIAT_OA_DATE,\n" +
                "                                  A.DEPT_ID,\n" +
                "                                  (SELECT B.NAME\n" +
                "                                      FROM MAS_DEPT B\n" +
                "                                     WHERE A.DEPT_ID = B.ID) DEPT_NAME,\n" +
                "                                  COUNT(*) COMPLAIN_NUM\n" +
                "                             FROM FN_CUSTOM_COMPLAIN A\n" +
                "                            WHERE A.INITIAT_OA_DATE IS NOT NULL\n" +
                "                            GROUP BY TO_CHAR(A.INITIAT_OA_DATE, 'YYYY-MM'),\n" +
                "                                     A.DEPT_ID)\n" +
                "                   WHERE INITIAT_OA_DATE = :DATE_END\n" +
                "                   ORDER BY COMPLAIN_NUM DESC)\n" +
                "          WHERE ROWNUM < 21) C\n" +
                "  LEFT JOIN (SELECT TO_CHAR(A.INITIAT_OA_DATE, 'YYYY-MM') INITIAT_OA_DATE,\n" +
                "                    A.DEPT_ID, COUNT(*) COMPLAIN_NUM\n" +
                "               FROM FN_CUSTOM_COMPLAIN A\n" +
                "              WHERE A.INITIAT_OA_DATE IS NOT NULL\n" +
                "                AND TO_CHAR(A.INITIAT_OA_DATE, 'YYYY-MM') = :DATE_START\n" +
                "              GROUP BY TO_CHAR(A.INITIAT_OA_DATE, 'YYYY-MM'), A.DEPT_ID) D\n" +
                "    ON C.DEPT_ID = D.DEPT_ID\n" +
                " WHERE 1 = 1\n" +
                " ORDER BY C.COMPLAIN_NUM DESC\n";

        return toJSONArray(find(sSQL, param));
    }

    public JSONArray customPlainReasonRank(JSONObject param){
        String sSQL = "SELECT C.INITIAT_OA_DATE, C.COMPLAIN_CATEGORY_NAME,\n" +
                "       C.COMPLAIN_NUM CUR_COMPLAIN_NUM,\n" +
                "       NVL(D.COMPLAIN_NUM, 0) PREV_COMPLAIN_NUM\n" +
                "\n" +
                "  FROM (SELECT *\n" +
                "           FROM (SELECT TO_CHAR(A.INITIAT_OA_DATE, 'YYYY-MM') INITIAT_OA_DATE,\n" +
                "                         A.COMPLAIN_CATEGORY,\n" +
                "                         GET_ENUMERATION_NAME(A.COMPLAIN_CATEGORY,\n" +
                "                                               'complainCategory') COMPLAIN_CATEGORY_NAME,\n" +
                "                         COUNT(*) COMPLAIN_NUM\n" +
                "                    FROM FN_CUSTOM_COMPLAIN A\n" +
                "                   WHERE A.INITIAT_OA_DATE IS NOT NULL\n" +
                "                     AND A.COMPLAIN_CATEGORY IS NOT NULL\n" +
                "                   GROUP BY TO_CHAR(A.INITIAT_OA_DATE, 'YYYY-MM'),\n" +
                "                            A.COMPLAIN_CATEGORY)\n" +
                "          WHERE INITIAT_OA_DATE = :DATE_END) C\n" +
                "  LEFT JOIN (SELECT TO_CHAR(A.INITIAT_OA_DATE, 'YYYY-MM') INITIAT_OA_DATE,\n" +
                "                    A.COMPLAIN_CATEGORY,\n" +
                "                    GET_ENUMERATION_NAME(A.COMPLAIN_CATEGORY,\n" +
                "                                          'complainCategory') COMPLAIN_CATEGORY_NAME,\n" +
                "                    COUNT(*) COMPLAIN_NUM\n" +
                "               FROM FN_CUSTOM_COMPLAIN A\n" +
                "              WHERE A.INITIAT_OA_DATE IS NOT NULL\n" +
                "                AND A.COMPLAIN_CATEGORY IS NOT NULL\n" +
                "                AND TO_CHAR(A.INITIAT_OA_DATE, 'YYYY-MM') = :DATE_START\n" +
                "              GROUP BY TO_CHAR(A.INITIAT_OA_DATE, 'YYYY-MM'),\n" +
                "                       A.COMPLAIN_CATEGORY) D\n" +
                "    ON C.COMPLAIN_CATEGORY_NAME = D.COMPLAIN_CATEGORY_NAME\n" +
                " WHERE 1 = 1\n" +
                " ORDER BY C.COMPLAIN_NUM DESC";
        return toJSONArray(find(sSQL, param));
    }



    /***
     * String数组转 ('1', '2', '3')
     */
    private String getInParam(JSONArray param){
        String str = param.stream().reduce("",(a, b) -> {
            if (a.equals("")) return "'" + b + "'";
            return a + ", '" + b + "'";
        },String::concat);

        return "(" + str + ")";
    }
}
